<?php
namespace App\Http\Controllers\Admin\Yqh;

use App\Service\Admin\Yqh\FlowService;
use Illuminate\Http\Request;

class FlowController extends BaseController
{
    //邀请函

    //列表
    public function index(Request $request)
    {
        $yqh_id = $request->post('yqh_id', 0);
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = FlowService::index($yqh_id, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['title'] = $request->post('title', '');
        $yqh = $request->post('yqh', '');
        $pas['cnt'] = $request->post('cnt', '');
        $pas['starttime'] = $request->post('starttime', '');
        $pas['endtime'] = $request->post('endtime', '');
        if ($id) {
            $res = FlowService::modify($id, $yqh, $pas);
        } else {
            $res = FlowService::add($yqh, $pas);
        }
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = FlowService::del($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}